package com.example.registration.service.impl;


import com.example.registration.dao.IndentMapper;
import com.example.registration.dao.LoginMapper;
import com.example.registration.exception.DataBaseSqlException;
import com.example.registration.pojo.Admin;
import com.example.registration.pojo.Hospital;
import com.example.registration.pojo.Indent;
import com.example.registration.service.IndentService;
import com.example.registration.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 登录
 *
 * @program: springboot_smbms
 * @Description: $
 * @Param: $
 * @return: $
 * @Author: xieyongde
 * @Date: 2019-08-15
 */
@Service
public class IndentServicelmap implements IndentService {
    @Autowired
    private IndentMapper indentMapper;

    public IndentMapper getIndentMapper() {
        return indentMapper;
    }

    public void setIndentMapper(IndentMapper indentMapper) {
        this.indentMapper = indentMapper;
    }

    //查询所有的订单数
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Integer count() throws DataBaseSqlException, Exception {
        Integer sum = indentMapper.count();
        if (sum >= 0) {
            return sum;
        } else {
            throw new DataBaseSqlException("发送异常。。。请稍后再尝试！");
        }
    }

    //制作分页条
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Map getPagingCount(Map map) throws DataBaseSqlException, Exception {
        Integer sum = indentMapper.getPagingCount(map);
        Map<String, Object> map1 = new HashMap<String, Object>();
        if (sum >= 0) {
            map1.put("msg", "查询成功");
            map1.put("result", true);
            map1.put("data", sum);
        } else {
            map1.put("result", false);
            map1.put("msg", "查询失败");
            throw new DataBaseSqlException("发送异常。。。请稍后再尝试！");
        }
        return map1;
    }

    //查询所有的订单
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Map showindent(Map map) throws DataBaseSqlException, Exception {
        List<Indent> indentList = (ArrayList<Indent>) indentMapper.showindent(map);
        HashMap<String, Object> map2 = new HashMap<String, Object>();
        if (indentList != null) {
            map2.put("msg", "查询成功");
            map2.put("result", true);
            map2.put("data", indentList);
        } else {
            map2.put("result", false);
            map2.put("msg", "查询失败");
            throw new DataBaseSqlException("发送异常。。。请稍后再尝试！");
        }
        return map2;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Map ComboBox() throws DataBaseSqlException, Exception {
        List<Hospital> hospitalList = indentMapper.ComboBox();
        Map<String, Object> map = new HashMap<String, Object>();
        if (hospitalList != null) {
            map.put("msg", "查询成功");
            map.put("result", true);
            map.put("data", hospitalList);
        } else {
            map.put("result", false);
            map.put("msg", "查询失败");
            throw new DataBaseSqlException("发送异常。。。请稍后再尝试！");
        }
        return map;
    }

    //查看指定id的订单信息
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Map show(Integer id) throws DataBaseSqlException, Exception {
        Indent indent = indentMapper.show(id);
        HashMap<String, Object> map = new HashMap<String, Object>();
        if (indent != null) {
            map.put("msg", "查询成功");
            map.put("result", true);
            map.put("data", indent);
        } else {
            map.put("result", false);
            map.put("msg", "查询失败");
            throw new DataBaseSqlException("发送异常。。。请稍后再尝试！");
        }
        return map;
    }
}
